package com.ninong.ker.log.service.impl;

import java.util.Arrays;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageInfo;
import com.ninong.ker.log.domain.FwLog;
import com.ninong.ker.log.mapper.FwLogMapper;
import com.ninong.ker.log.service.FwLogService;
import com.ninong.ker.log.service.dto.FwLogDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import com.github.pagehelper.PageHelper;



@Service
@org.apache.dubbo.config.annotation.Service(version = "1.0.0")
public class FwLogServiceImpl extends ServiceImpl<FwLogMapper, FwLog> implements FwLogService {

    @Override
	public PageInfo<FwLog> listPage(FwLogDTO dto) {
		PageHelper.startPage(dto.getCurrentPage(), dto.getPageSize());
		LambdaQueryWrapper<FwLog> query = new LambdaQueryWrapper<>();
		if(StringUtils.isNotEmpty(dto.getUsername())){
			query.like(FwLog::getUsername,dto.getUsername());
		}
		if(StringUtils.isNotEmpty(dto.getLogType())){
			query.eq(FwLog::getLogType,dto.getLogType());
		}
		query.orderByDesc(FwLog::getCreateTime);
		List<FwLog> FwLogs = baseMapper.selectList(query);
		return new PageInfo<FwLog>(FwLogs);
	}

	@Override
	public void delete(String[] ids) {
		List<String> idList = Arrays.asList(ids);
		baseMapper.deleteBatchIds(idList);
	}

	@Override
	public void insert(FwLog entity) {
		//校验自行实现
		save(entity);
	}

	@Override
	public FwLog get(String id) {
		FwLog entity = baseMapper.selectById(id);
		if (ObjectUtils.isEmpty(entity)) {
			entity = new FwLog();
		}
		return entity;
	}

}